package com.ziilion;
 
import java.io.IOException;
 
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
 
public class NewTopic extends Activity implements SurfaceHolder.Callback{
 
Camera myCamera;
SurfaceView previewSurfaceView;
SurfaceHolder previewSurfaceHolder;
boolean previewing = false;
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.newtopic);
       
       getWindow().setFormat(PixelFormat.UNKNOWN);    
       previewSurfaceView = (SurfaceView)findViewById(R.id.previewsurface);
       previewSurfaceHolder = previewSurfaceView.getHolder();
       previewSurfaceHolder.addCallback(this);
       previewSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
       
       ImageView buttonTakePicture = (ImageView)findViewById(R.id.takebutton);
       buttonTakePicture.setOnClickListener(new Button.OnClickListener(){
    	   @Override
    	   public void onClick(View arg0) {
    		   // TODO Auto-generated method stub
    		   myCamera.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);
    		   Intent intent=new Intent();
    		   intent.setClass(NewTopic.this,NewTopic1.class);
    		   NewTopic.this.startActivity(intent);
    		   }
    	   }
       );
       }
   ShutterCallback shutterCallback = new ShutterCallback(){
 
	   @Override
	   public void onShutter() {
		   // TODO Auto-generated method stub
		   }
	   };
	   
	   PictureCallback rawPictureCallback = new PictureCallback(){
		   @Override
		   public void onPictureTaken(byte[] arg0, Camera arg1) {
			   // TODO Auto-generated method stub
			   }
		   };
		   PictureCallback jpegPictureCallback = new PictureCallback(){
			   @Override
			   public void onPictureTaken(byte[] arg0, Camera arg1) {
				   // TODO Auto-generated method stub
				   Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);   
				   }
			   };
			   @Override
			   public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
				   // TODO Auto-generated method stub
				   if(previewing){
					   myCamera.stopPreview();
					   previewing = false;
					   }
				   try {
					   myCamera.setPreviewDisplay(arg0);
					   myCamera.startPreview();
					   previewing = true;
					   } catch (IOException e) {
						   // TODO Auto-generated catch block
						   e.printStackTrace();
						   }
					   }
			   @Override
			   public void surfaceCreated(SurfaceHolder arg0) {
				   // TODO Auto-generated method stub
				   myCamera = Camera.open();
				   }
			   @Override
			   public void surfaceDestroyed(SurfaceHolder arg0) {
				   // TODO Auto-generated method stub
				   myCamera.stopPreview();
				   myCamera.release();
				   myCamera = null;
				   previewing = false;
				   }
}